import useSlide from './useSlide'
import useAnnotation from './useAnnotation'

export default function useMain() {
    document.querySelector('html').style.background = "rgba(0, 0, 0, 0)"
    document.body.style.background = "rgba(0, 0, 0, 0)"

    // const params = new URLSearchParams(window.location.search)
    // const uuid = params.get('uuid')
    // const token = params.get('token')

    // localStorage.setItem("access_token", token)

    const { slideData, slideId } = useSlide()

    // const { annotationList, slideId: slideId2 } = useAnnotation()

    
    recivedMessage({ slideId })

    return {
        slideData,
        // annotationList
    }
}

function recivedMessage(params) {
    window.unityToHtml = (msg) => {
        const msg2 = JSON.parse(msg)
        switch (msg2.type) {
            case "login":
                localStorage.setItem("access_token", msg2.data.token)
                break
            case "load":
                params.slideId.value = msg2.data.uuid
                // params.slideId2.value = msg2.data.uuid
                break
            default:
                console.warn("未知的消息类型", msg)
        }
    }
}


